package com.wd.jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.List;

import org.springframework.stereotype.Component;

@Component
public class LiveStarService extends AbstractService {

	public void insertData(List<String[]> dataList) {

		if (dataList == null || dataList.isEmpty())
			return;
		Connection con = null;
		PreparedStatement pst = null;
		try {
			con = getConnection();
			con.setAutoCommit(false);// 手动提交
			pst = con.prepareStatement("insert into app_live_star(platform,star,get_time,watch_num,game_name) values(?,?,now(),?,?)");
			for (String[] array : dataList) {
				pst.setString(1, array[3]);
				pst.setString(2, array[1]);
				Double num = null;
				if (array[2].indexOf("万") > 0) {
					num = Double.parseDouble(array[2].replaceAll("万", "")) * 1000;
				} else {
					num = Double.parseDouble(array[2].replaceAll("万", ""));
				}
				pst.setDouble(3, num);
				pst.setString(4, array[0]);
				pst.execute();
			}
			con.commit();
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			CloseConnection(con);
		}
	}
}
